//
//  ShellHomeView.m
//  ShellWallert
//
//  Created by lvzhao on 2019/10/3.
//  Copyright © 2019 VV. All rights reserved.
//

#import "ShellHomeView.h"
#import "ShellHomeViewModel.h"
#import "ShellRegionView.h"
#import "ShellHomeUserView.h"
#import "ShellMilestoneView.h"
#import "ShellTotalRewardView.h"
#import "LZMJDIYRefreshHeader.h"
#import "OYCountDownManager.h"


@interface ShellHomeView()

@property (nonatomic,strong) ShellHomeViewModel *viewModel;


@end

@implementation ShellHomeView

- (instancetype)initViewModel:(LZBaseViewModel *)viewModel
{
    self = [super init];
    if (self) {
        self.viewModel = (ShellHomeViewModel *)viewModel;
        [self setupView];
    }
    return self;
}

#pragma mark - setupView
- (void)setupView{
    
    
    // 启动倒计时管理
    [kCountDownManager start];
    
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    //内容
    UIView *contentView = [[UIView alloc] init];
    [scrollView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.and.right.equalTo(scrollView).with.insets(UIEdgeInsetsZero);
        make.width.equalTo(scrollView);
    }];
    
    ///!!!:区域图
    ShellRegionView *regionView = [[ShellRegionView alloc] initViewModel:self.viewModel];
    [contentView addSubview:regionView];
    [regionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(K_NAVHEIGHT);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(251);
    }];
    
    ///!!!:我的信用 && 我的算力
    ShellHomeUserView *userView = [[ShellHomeUserView alloc] initViewModel:self.viewModel];
    [contentView addSubview:userView];
    [userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(regionView.mas_bottom);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(70);
    }];
    
    ///!!!:矿池总奖励
    ShellTotalRewardView *rewardView = [[ShellTotalRewardView alloc] initViewModel:self.viewModel];
    [contentView addSubview:rewardView];
    [rewardView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(userView.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(150);
    }];
    
    ///!!!:里程碑
    ShellMilestoneView *milestoneView = [[ShellMilestoneView alloc] initViewModel:self.viewModel];
    [contentView addSubview:milestoneView];
    [milestoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(rewardView.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(140);
    }];
    
    
    @weakify(self);
    LZMJDIYRefreshHeader *header = [LZMJDIYRefreshHeader headerWithRefreshingBlock:^{
        @strongify(self)
        [self.viewModel getStaticInfo:NO];
           
    }];
    scrollView.mj_header = header;
         
    [contentView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(milestoneView.mas_bottom).mas_offset(34);
    }];
    
    [self.viewModel.reloadSubject subscribeNext:^(id  _Nullable x) {
        scrollView.mj_header.state = MJRefreshStateIdle;
    }];
    
}

#pragma mark - custool

#pragma mark - get && set

@end
